package net.crozz.openapi.weibo;

import com.google.gson.reflect.TypeToken;
import net.crozz.openapi.ApiException;
import net.crozz.openapi.http.Param;
import net.crozz.openapi.http.Requester;
import net.crozz.openapi.weibo.model.user.Resp_counts;
import net.crozz.openapi.weibo.model.user.Resp_domain_show;
import net.crozz.openapi.weibo.model.user.Resp_show;

import java.util.List;

public class Users {

    private Requester client;
    private String    baseURL;

    Users(Requester client, String baseURL) {
        this.client = client;
        this.baseURL = baseURL;
    }

    /**
     * 根据用户ID获取用户信息<br/>
     * http://open.weibo.com/wiki/2/users/show<br/>
     * 参数uid与screen_name二者必选其一，且只能选其一
     *
     * @param access_token access_token
     * @param uid          需要查询的用户ID
     * @param screen_name  需要查询的用户昵称
     */
    public Resp_show show(String access_token, String uid, String screen_name) throws ApiException {
        return client.getObj(
                Resp_show.class,
                baseURL + "users/show.json",
                Param.newParam("access_token", access_token),
                Param.newParam("uid", uid),
                Param.newParam("screen_name", screen_name)
        );
    }

    /**
     * 通过个性化域名获取用户资料以及用户最新的一条微博<br/>
     * http://open.weibo.com/wiki/2/users/domain_show
     *
     * @param domain 需要查询的个性化域名。
     */
    public Resp_domain_show domain_show(String access_token, String domain) throws ApiException {
        return client.getObj(
                Resp_domain_show.class,
                baseURL + "users/domain_show.json",
                Param.newParam("access_token", access_token),
                Param.newParam("domain", domain)
        );
    }

    /**
     * 批量获取用户的粉丝数、关注数、微博数<br/>
     * http://open.weibo.com/wiki/2/users/counts
     *
     * @param uids 需要获取数据的用户UID，多个之间用逗号分隔，最多不超过100个
     */
    public List<Resp_counts> counts(String access_token, String uids) throws ApiException {
        return client.getObj(
                new TypeToken<List<Resp_counts>>() {}.getType(),
                baseURL + "users/counts.json",
                Param.newParam("access_token", access_token),
                Param.newParam("uids", uids)
        );
    }
}
